/**
 * LogKaiyuanAgentService.java
 * Copyright(C) 1949++ 中华人民共和国
 * 深圳市盛开互联网金融顾问有限公司.
 * All rights reserved.
 * E-mail:server@skjr.net
 * SKDate:2017-11-16 17:28:58
 */
package com.huamao.zh.service.impl;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.huamao.zh.base.PageWrapper;
import com.huamao.zh.constants.KaiyuanAgentType;
import com.huamao.zh.mapper.LogKaiyuanAgentMapper;
import com.huamao.zh.model.LogKaiyuanAgent;
import com.huamao.zh.service.LogKaiyuanAgentService;

@Service
@Transactional
public class LogKaiyuanAgentServiceImpl implements LogKaiyuanAgentService {

	@Autowired
	private LogKaiyuanAgentMapper logKaiyuanAgentMapper;

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanAgent add(LogKaiyuanAgent logKaiyuanAgent) throws Exception {
		logKaiyuanAgentMapper.add(logKaiyuanAgent);
		return logKaiyuanAgent;
	}

	public LogKaiyuanAgent add(int type, int fromId, int agentId, String orderNo, int scoreType, BigDecimal preKaiyuan,
			int kaiyuanType, BigDecimal getKaiyuan, String remark) throws Exception {
		LogKaiyuanAgent logKaiyuan = new LogKaiyuanAgent();
		logKaiyuan.setType(type);
		logKaiyuan.setAgentId(agentId);
		logKaiyuan.setOrderNo(orderNo);
		logKaiyuan.setPreKaiyuan(preKaiyuan);
		logKaiyuan.setKaiyuanType(kaiyuanType);
		logKaiyuan.setKaiyuan(getKaiyuan);
		logKaiyuan.setRemark(remark);
		logKaiyuan.setDataFlag(1);
		logKaiyuan.setCreateTime(new Date());
		logKaiyuanAgentMapper.add(logKaiyuan);
		return logKaiyuan;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanAgent addSelective(LogKaiyuanAgent logKaiyuanAgent) throws Exception {
		logKaiyuanAgentMapper.addSelective(logKaiyuanAgent);
		return logKaiyuanAgent;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int delete(Map<String, Object> map) {
		return logKaiyuanAgentMapper.delete(map);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int update(LogKaiyuanAgent logKaiyuanAgent) throws Exception {
		return logKaiyuanAgentMapper.update(logKaiyuanAgent);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public int updateSelective(LogKaiyuanAgent logKaiyuanAgent) throws Exception {
		return logKaiyuanAgentMapper.updateSelective(logKaiyuanAgent);
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public LogKaiyuanAgent get(Integer id) {
		LogKaiyuanAgent logKaiyuanAgent = logKaiyuanAgentMapper.get(id);
		return logKaiyuanAgent;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public PageWrapper<LogKaiyuanAgent> search(PageWrapper<LogKaiyuanAgent> pageWrapper) {
		List<LogKaiyuanAgent> logKaiyuanAgents = logKaiyuanAgentMapper.search(pageWrapper);
		pageWrapper.setList(logKaiyuanAgents);
		return pageWrapper;
	}

	/**
	 * 功能说明： Author： SKDate:2017-11-16 17:28:58
	 */
	public List<LogKaiyuanAgent> queryList(Map<String, Object> map) {
		return logKaiyuanAgentMapper.queryList(map);
	}

	/**
	 * 功能说明：生成日志专用 Author：spring Date：2017/11/21 8:54
	 */
	public LogKaiyuanAgent getLogLogKaiyuanAgent(KaiyuanAgentType type, int agentId, String orderNo,
			BigDecimal preLogKaiyuanAgent, BigDecimal LogKaiyuanAgent, String remark) {
		LogKaiyuanAgent logKaiyuanAgent = new LogKaiyuanAgent();
		logKaiyuanAgent.setType(type.getCode());
		logKaiyuanAgent.setAgentId(agentId);
		logKaiyuanAgent.setOrderNo(orderNo);
		logKaiyuanAgent.setPreKaiyuan(preLogKaiyuanAgent);
		logKaiyuanAgent.setKaiyuan(LogKaiyuanAgent);
		logKaiyuanAgent.setRemark(remark);
		logKaiyuanAgent.setDataFlag(1);
		logKaiyuanAgent.setCreateTime(new Date());
		return logKaiyuanAgent;
	}

	/**
	 * 功能说明：添加 新增 流水 Author：spring Date：2017/11/21 8:56
	 */
	@Override
	public LogKaiyuanAgent sumLogKaiyuanAgent(KaiyuanAgentType type, Integer agentId, String orderNo,
			BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogKaiyuanAgent logKaiyuanAgent = getLogLogKaiyuanAgent(type, agentId, orderNo, preCash, cash, remark);
		logKaiyuanAgent.setKaiyuanType(1);
		return this.add(logKaiyuanAgent);
	}

	/**
	 * 功能说明：添加 减少 流水 Author：spring Date：2017/11/21 8:56
	 */
	@Override
	public LogKaiyuanAgent subtractLogKaiyuanAgent(KaiyuanAgentType type, Integer agentId, String orderNo,
			BigDecimal preCash, BigDecimal cash, String remark) throws Exception {
		LogKaiyuanAgent logKaiyuanAgent = getLogLogKaiyuanAgent(type, agentId, orderNo, preCash, cash, remark);
		logKaiyuanAgent.setKaiyuanType(0);
		return this.add(logKaiyuanAgent);
	}

}